#ifndef COMMON_GPU_H
#define COMMON_GPU_H

#include <thrust/device_vector.h>


// hash table implementation
#define MAX_HASH_KEY 128
#define SORTED_SHARED_SIZE 5 // the basic sorting unit
// output_index has number of element: number of blks * number of MAX_HASH_KEY
// first (number of threads) elements denote the index for hash key 0
// here number of threads per blk must be equal to MAX_HASH_KEY
__global__ void hash_partition(int* data, int data_size, int num_of_blks,int* output_index,int num_rounds);
__global__ void output_hash_table(int* data, int data_size, int num_of_blks,int* output_index, int* output_table);
void test_hash_table();

// hash table index contain the end index of the hash value
// only multiple of hash index offset in the hash index is valid 
__global__ void sort_within_blks(int* hash_table, int* hash_index, int hash_index_offset,int* sorted_hash_table,int num_rounds);

__global__ void sort_within_blks_tuned(int* hash_table, int* hash_index, int hash_index_offset,int* sorted_hash_table, int num_rounds, int MAX_BITS);

// return the new data size
int remove_duplicate(thrust::device_vector<int>& dvec,int data_size,int num_rounds);

#endif 